package com.swf.seed.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 项目名称：SqlToHtml 类名称：PathUtils 类描述：存放相关路径名称 创建人：Weifeng Shen 创建时间：2012-12-25
 * 下午2:21:15
 * 
 * @version 1.0
 */
public final class FwsPathUtils{
	private static final Logger logger = LoggerFactory
			.getLogger(FwsPathUtils.class);
	/**
	 * 禁用默认构造器	
	 */
	private FwsPathUtils() {
	}

	/**
	 * method:DealSeparator{处理路径，将'\'替换为'/',最后一位为 '/'}
	 * 
	 * @param oldPath
	 * @return String newPath
	 */
	public static String DealSeparator(String oldPath) {
		String newPath = "";
		if (oldPath != null) {
			newPath = oldPath.replace("\\", "/").trim();
			char lastchar = newPath.charAt(newPath.length() - 1);
			newPath = '/' == lastchar ? newPath : newPath + "/";
			return newPath;
		}
		logger.warn("Path shouldn't be null");
		return null;
	}

	/**
	 * method:DealSeparator{处理路径，将'\'替换为'/',最后一位为 '/'}
	 * 
	 * @param oldPath
	 * @return String newPath
	 */
	public static String DealSeparatorNone(String oldPath) {
		String newPath = "";
		if (oldPath != null) {
			newPath = oldPath.replace("\\", "/").trim();
			char lastchar = newPath.charAt(newPath.length() - 1);
			newPath = '/' == lastchar ? newPath.substring(0,
					newPath.length() - 1) : newPath;
			return newPath;
		}
		logger.warn("Path shouldn't be null");
		return null;
	}

	/**
	 * 判断文件路径是否是相对路径
	 * 简单判断以盘符:开头 或 /开头
	 * @param path
	 * @return
	 * @throws FwsException
	 */
	public static boolean isRelativePath(String path){
		if (path == null){
			logger.error("路径不能为空");
			return false;
		}
		return !(path.matches("^[a-zA-Z]:.*$")||path.matches("^/.*$"));
	}
	
}
